<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <link rel="stylesheet" href="/assets/css/layui.css">
    <link rel="stylesheet" href="/assets/css/view.css"/>
    <title></title>
</head>
<body class="layui-view-body">
    <div class="layui-content">
        <div class="layui-row">
            <div class="layui-card">
                <div class="layui-card-header">分类表单</div>
                <form class="layui-form layui-card-body" method="post" action="">
                  @csrf
                  <input type="hidden" name="p_id" value="{{$id}}">
                  <div class="layui-form-item">
                    <label class="layui-form-label">父级名称</label>
                    <div class="layui-input-block">
                      <input type="text" name="name" value="{{$name}}" disabled="disabled" style="cursor:not-allowed;" autocomplete="off" class="layui-input">
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <label class="layui-form-label">名称</label>
                    <div class="layui-input-block">
                      <input type="text" name="name" required  lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input">
                    </div>
                  </div>
                  <div class="layui-form-item">
                    <div class="layui-input-block">
                      <button class="layui-btn layui-btn-blue" lay-submit lay-filter="formDemo">立即提交</button>
                      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                  </div>
                </form>  
            </div>
        </div>
    </div>
</body>
<script src="/assets/layui.all.js"></script>
<script>
  var form = layui.form
    ,layer = layui.layer
    ,$=layui.jquery;
    //监听提交
    form.on('submit(formDemo)', function(data){
      $.ajax({   
        url:"{{route('admin.addsubcateup')}}",
        method:'post',
        data:data.field,
        dataType:'JSON',
        success:function(res){
          if(res.code=='0'){
            var findex = parent.layer.getFrameIndex(window.name);
            parent.location.reload();
            parent.layer.close(findex);
          }else{
            alert(res.msg);
          }
        },
        error:function (data) {
          layer.msg(JSON.stringify(data.field));
        }
      });
      return false;
    });
</script>
</html>